package com.cat.dynamicPlanning02;

/**
*   @description https://leetcode.cn/problems/count-number-of-teams/?envType=problem-list-v2&envId=binary-indexed-tree
*   @author 曲大人的喵
*   @create 2025/11/5 18:24
*   @since JDK17
*/

public class Solution42 {
    public int numTeams(int[] rating) {
        int n = rating.length, ans = 0;
        for (int i = 1; i < n; i++) {
            int l0 = 0, l1 = 0, r0 = 0, r1 = 0;
            for (int j = 0; j < n; j++) {
                if (j < i) {
                    l0 += rating[j] < rating[i] ? 1 : 0;
                    l1 += rating[j] > rating[i] ? 1 : 0;
                } else {
                    r0 += rating[j] > rating[i] ? 1 : 0;
                    r1 += rating[j] < rating[i] ? 1 : 0;
                }
            }
            ans += l0 * r0 + l1 * r1;
        }

        return ans;
    }
}
